package com.huan.loadbalancer.controller;

import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
import com.huan.loadbalancer.feign.FeignProvider;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 消费者控制器
 *
 * @author huan.fu
 * @date 2023/6/19 - 22:21
 */
@RestController
public class ConsumerController {

    @Resource
    private FeignProvider feignProvider;
    @Resource
    private NacosDiscoveryProperties nacosDiscoveryProperties;

    @GetMapping("fetchProviderServerInfo")
    public Map<String, String> fetchProviderServerInfo() {
        Map<String, String> ret = new HashMap<>(4);
        ret.put("consumer信息", nacosDiscoveryProperties.getIp() + ":" + nacosDiscoveryProperties.getPort());
        ret.put("provider信息", feignProvider.fetchServerInfo());
        return ret;
    }
}
